package frankenstein.datastructures;
import java.util.*;


public class Evolution extends ParentModel {

	private ArrayList<Period> periods;
	private Cromosome responsibilities;
	private String name;
	private int terminatingGeneration;
	private long fitnessValue;
	private String usecaseModelURL = null;
	
	//--------------hadaytullah	
	/**
	 * the domain model for the evolution
	 */
	private InputModels inputModels;
	
	
	public InputModels getInputModels() {
		return inputModels;
	}
	public void setInputModels(InputModels inputModels) {
		this.inputModels = inputModels;
	}
	
	
    public Evolution createClone(){
    	
    	Evolution clone = new Evolution();
    	
    	clone.setFilePath(filePath);
    	clone.setFitnessValue(fitnessValue);
    	clone.setInputModels(inputModels.createClone());
    	//clone.setLastGeneration(getLastPeriod().getLastGeneration());
    	//clone.setLastPeriod(getLastPeriod());
    	clone.setName(name);
    	
    	for (Period period: periods){
    		clone.getPeriods().add(period.createClone());
    	}
    	
    	
    	
    	return clone;
    	
    	
    }
	///--------------------------
	public String getUsecaseModelURL() {
		return usecaseModelURL;
	}
	public void setUsecaseModelURL(String modelURL) {
		this.usecaseModelURL = modelURL;
	}
	/**
	 * file path on disk
	 */
	String filePath="";
	
	
	public Evolution(){
		///hadaytullah
		inputModels = new InputModels();		
		/////----
		periods = new ArrayList<Period>();
	}
	public Evolution(String namestr) {
		///hadaytullah
		inputModels = new InputModels();		
		/////----
		
		name = namestr;
		periods = new ArrayList<Period>();
	}
	public ArrayList<Period> getPeriods() {
		return periods;
	}
	public void setPeriods(ArrayList<Period> periods) {
		this.periods = periods;
	}
	public void addPeriod(Period period){
		this.periods.add(period);
	}
	public Cromosome getResponsibilities() {
		return responsibilities;
	}
	public void setResponsibilities(Cromosome responsibilities) {
		this.responsibilities = responsibilities;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Generation getLastGeneration() {
		return getLastPeriod().getLastGeneration();
	}
	public void setLastGeneration(Generation lastGeneration) {
		getLastPeriod().setLastGeneration(lastGeneration);
	}
	public int getTerminatingGeneration(){
		
		terminatingGeneration = 0;
		
		for(Period p: periods){
			terminatingGeneration = terminatingGeneration + p.getTerminatingGeneration();
		}
		
		return terminatingGeneration;
	}
	public void setTerminatingGeneration(int generation){
		this.terminatingGeneration = generation;
	}
	public long getFitnessValue() {
		return fitnessValue;
	}
	public void setFitnessValue(long fitnessValue) {
		this.fitnessValue = fitnessValue;
	}
	public String getFilePath() {
		return filePath;
	}
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	
	public Period getLastPeriod(){
		return periods.get(periods.size()-1);
	}
	
	public Period getLatestPeriod(){
		Period current = this.periods.get(0);
		Period temp = null;
		boolean quitSearch = false;
		for(int i = 0; i<this.periods.size()&&!quitSearch; i++){
			temp = this.periods.get(i);
			if(temp.getGenerations().size()>0){
				current = temp;
			}
			else{
				quitSearch = true;
			}
		}
		return current;
	}

	public void setLastPeriod(Period lastPeriod){
		periods.set(periods.size()-1, lastPeriod);
	}
	public void setPeriod(int index, Period period){
		periods.set(index, period);
	}
}
